<template>
	<view class="wrap" style="padding-bottom: 60px;">
		<!-- 顶部栏 -->
		<view class="header">
			<view class="userinfo" @click="navTo('/pages/sys/book/personal-details')">
				<view class="image">
					<u-avatar size="80" :src="msgInfo.img" />
				</view>
				<view class="info" style="flex:1;display: flex;justify-content: space-between;">
					<view>
						<view class="username">{{type}}</view>
						<view class="usercode">来自：{{msgInfo.nickName}}</view>
					</view>
					<u-tag :text="getStatus" shape="circle" :type="getType" style="height: 55rpx;" />
				</view>
			</view>
		</view>
		<u-tabs :list="list" :is-scroll="false" :current="current" @change="change" />
		<!-- 当前订单 -->
		<view v-if="current === 0">
			<u-gap height="20" bg-color="#f5f5f5"></u-gap>
			<u-cell-group class="datails-examine">
				<u-cell-item title="申请编号" :label="msgInfo.messageDetail.id" :arrow="false" :border-bottom="false" />
				<u-cell-item title="申请人身份" :label="role" :arrow="false" :border-bottom="false" />
				<u-cell-item title="申请类型" :label="type" :arrow="false" :border-bottom="false" />
				<u-cell-item title="申请时间" :label="msgInfo.messageDetail.time" :arrow="false" :border-bottom="false" />
				<u-cell-item title="备注" :label="msgInfo.messageDetail.message" :arrow="false" :border-bottom="false" />
			</u-cell-group>
			<u-gap height="20" bg-color="#f5f5f5" />
			<u-row gutter="32" class="bottom-box" justify="center">
				<u-col span="5">
					<view>
						<u-button :plain="true" type="primary" shape="circle" @click="reject">拒绝</u-button>
					</view>
				</u-col>
				<u-col span="5">
					<view>
						<u-button type="primary" shape="circle" @click="admit">确定</u-button>
					</view>
				</u-col>
			</u-row>
		</view>
		<!-- 历史订单 -->
		<view v-if="current === 1">
			<view class="search">
				<u-search v-model="keywords" @custom="search" @search="search"></u-search>
			</view>
			<u-card v-for="(item,index) in 5" :key="index" class="task-list-item" :border="false" padding="20"
				margin="20rpx">
				<view slot="head" style="display: flex;align-items: center;justify-content: space-between;">
					<view style="display: flex;align-items: center;font-size: 30rpx;">
						<image class="user-images" src="/static/aidex/images/user06.png"></image>比利的授课申请
					</view>
					<view style="color: #999999;font-size: 22rpx;">2022年7月24日</view>
				</view>
				<view class="" slot="body">
					<u-row gutter="16">
						<u-col span="12">
							<view class="apply-text"><span>授课类型：</span>线下</view>
						</u-col>
						<u-col span="12">
							<view class="apply-text"><span>开始时间：</span>2021年10月25日14:30</view>
						</u-col>
						<u-col span="12">
							<view class="apply-text"><span>结束时间：</span>2021年10月27日14:30</view>
						</u-col>
					</u-row>
				</view>
				<view class="apply-list-foot" slot="foot" style="text-align: right;color: #58ca93;">
					申请通过
				</view>
			</u-card>
		</view>

		<!-- 提示框 -->
		<u-toast ref="uToast" />

	</view>
</template>
<script>
	export default {
		data() {
			return {
				status: 0,
				keywords: '',
				list: [{
					name: '申请详情'
				}, {
					name: '历史申请',
				}],
				current: 0,
				status: 'loadmore',
				msgInfo: {},
				type: '',
				role: ''
			}
		},
		methods: {
			change(index) {
				this.current = index;
			},
			navTo(url) {
				uni.navigateTo({
					url: url
				});
			},
			reject() {
				this.$u.toast('拒绝')
				this.status = 2
			},

			agreeFocus() {
				this.$u.api.message.agreeFocus({
						id: this.msgInfo.messageDetail.mid
					})
					.then(res => {
						if (res.code === 200) {
							this.$refs.uToast.show({
								title: '关注成功',
								type: 'success',
							})
						} else {
							this.$refs.uToast.show({
								title: '关注失败',
								type: 'error',
							})
						}
					});
			},
			admit() {
				if (this.type === '好友申请') {
					console.log("admit")
					this.agreeFocus()
				} else if (this.type === '授课申请') {
					agreeTeach()
				} else if (this.type === '签约申请') {
					agreeSign()
				} else if (this.type === '解约申请') {
					rejectSign()
				}
			}

		},
		computed: {
			getStatus() {
				if (this.status === 2) {
					return '已拒绝'
				} else if (this.status === 1) {
					return '已同意'
				} else {
					return '待同意'
				}
			},
			getType() {
				if (this.status === 2) {
					return 'error'
				} else if (this.status === 1) {
					return 'success'
				} else {
					return 'warning'
				}
			}
		},
		onLoad(val) {
			this.msgInfo = this.$store.state.doMsgList[val.index]
			if (val.type === '1') {
				this.type = '好友申请'
			} else if (val.type === '2') {
				this.type = '授课申请'
			} else if (val.type === '3') {
				this.type = '签约申请'
			} else if (val.type === '4') {
				this.type = '解约申请'
			}
			let rid = this.msgInfo.rid
			if (rid === 101) {
				this.role = '普通会员'
			} else if (rid === 102) {
				this.role = '金牌教练'
			} else if (rid === 103) {
				this.role = '高级场馆'
			}
		}

	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f5f5f5;
	}

	.wrap .search {
		background: #ffffff;
	}

	.apply-text {
		font-size: 28rpx;
		color: #333333;

		span {
			color: #999999;
		}
	}

	.user-images {
		width: 28px;
		height: 28px;
		margin-right: 8px;
	}

	.apply-list-foot {
		font-size: 28rpx;
	}

	.personnel-list {
		display: flex;
		align-items: center;
		flex-wrap: wrap;

		.personnel-user {
			position: relative;
			margin: 5px 9px 0;
		}

		.user-images {
			width: 32px;
			height: 32px;
			margin-right: 0;

		}

		.iconfont {
			position: absolute;
			top: -12px;
			right: -5px;
			color: #FE0100;
		}
	}

	.header {
		background-color: #ffffff;

		.userinfo {
			display: flex;
			padding: 20rpx 20rpx 10rpx;

			.image {
				flex-shrink: 0;
				width: 80rpx;
				height: 80rpx;

				image {
					border-radius: 100%;
					width: 100%;
					height: 100%;
				}
			}

			.info {
				display: flex;
				flex-flow: wrap;
				padding-left: 30rpx;
				color: #333333;

				.username {
					width: 100%;
					font-size: 32rpx;
				}

				.usercode {
					padding: 0;
					font-size: 24rpx;
					color: #999999;
				}
			}
		}

		.logout {
			flex-shrink: 0;
			position: absolute;
			right: 70rpx;
			top: 65rpx;

			.u-btn {
				font-size: 30rpx;
			}
		}
	}

	.u-node {
		width: 44rpx;
		height: 44rpx;
		border-radius: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: #d0d0d0;
	}

	.u-order-title {
		color: #333333;
		font-weight: bold;
		font-size: 30rpx;
	}

	.u-order-desc {
		color: rgb(150, 150, 150);
		font-size: 28rpx;
		margin-bottom: 6rpx;
	}

	.u-order-time {
		color: rgb(200, 200, 200);
		font-size: 26rpx;
	}
</style>
